home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 13651 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.8 KB

  1. Path: druid.borland.com!usenet
  2. From: pete@borland.com (Pete Becker)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: my program has a mind of its own (no really)
  5. Date: 9 Apr 1996 16:00:01 GMT
  6. Organization: Borland International
  7. Message-ID: <4ke1i2$j37@druid.borland.com>
  8. References: <sbb-0904960305370001@ts13-06.upenn.edu>
  9. NNTP-Posting-Host: pbecker.borland.com
  10. Mime-Version: 1.0
  11. Content-Type: Text/Plain; charset=ISO-8859-1
  12. X-Newsreader: WinVN 0.99.5
  13.  
  14. In article <sbb-0904960305370001@ts13-06.upenn.edu>, sbb@eniac.seas.upenn.edu 
  15. says...
  16. >
  17. >I am writing a program (with cc as compiler) which has a number of arrays,
  18. >which I have been verry careful to initialize with values, to avoid
  19. >segmentation faults. The main part of the program is a loop beginning with
  20. >an fgets statement to read in the next line from a file. Under certain
  21. >circumstances, the program returns "Segmentation Fault" just as it reaches
  22. >the beginning of this loop. When I put it a printf statement right before
  23. >the loop to see how far it actually got, it worked. 
  24. >
  25. >printf("something\n");
  26. >
  27. >When I removed "something", leaving just
  28. >
  29. >printf("\n");
  30. >
  31. >it gave me a segmentation fault again. I tried the same tactic at the
  32. >beginning of the loop, and found that the program worked with a long word
  33. >in the printf statement, but not a short word. Needless to say, I am
  34. >slightly bewildered by this behavior, as the printf statement, at least to
  35. >my knowledge, has no effect on my arrrays. If anyone has had a similar
  36. >experience, or knows what's going on here, I'd be extremely grateful.
  37.  
  38. These are typical symptoms of a program that contains a bad pointer. Either 
  39. it hasn't been initialized or it points to freed memory. When it seems to work 
  40. it's just that the pointer happens to be pointing to something harmless. This 
  41. kind of problem can be tough to track down. Good luck!
  42.  
  43.